<template>
  <div id="app">
    <!-- 头部-用户信息 -->
    <Topbar :key="topbarKey"></Topbar>
    <!-- 头部-导航切换 -->
    <Header></Header>
    <keep-alive>
      <router-view @updateKey="updateKeyFn" />
    </keep-alive>
    <!-- 底部 -->
    <Footer></Footer>
    <!-- 调用登录组件 -->
    <Login v-show="isShowLoginModal"></Login>
    <!-- 提示框 -->
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
  </div>
</template>

<script>
import Topbar from '@/components/Topbar.vue'
import Header from '@/components/Header.vue'
import Footer from '@/components/Footer.vue'
import Login from '@/components/Login.vue'
import Toast from '@/components/Toast.vue'
// vuex
import { mapState } from 'vuex'
// import request from '@/request/request'
// import { JinpingAPI, RemenAPI } from '@/request/api'
export default {
  data() {
    return {
      topbarKey: 0
    }
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast
  },
  computed: {
    ...mapState({
      isShowLoginModal: (state) => state.showModal.isShowLoginModal,
      isShowToast: (state) => state.showToast.isShowToast
    })
  },
  async created() {
    /* request
      .get('/products/recommend', {
        headers: {
          token: '123'
        }
      })
      .then((res) => {
        // console.log(res)
      })
    let res1 = await JinpingAPI()
    console.log('精品：', res1)
    let res2 = await RemenAPI()
    console.log('热门：', res2) */
  },
  watch: {
    '$route.path': {
      handler(newVal, oldVal) {
        if (oldVal != '/') {
          this.topbarKey++
        }
      }
    }
  },
  methods: {
    updateKeyFn() {
      this.topbarKey++
    }
  }
}
</script>

<style lang="less">
// 进入效果
.slide-enter,
.slide-leave-to {
  opacity: 0;
}
// 过渡效果
.slide-enter-active {
  transition: opacity 0.2s linear;
}
.slide-leave-active {
  transition: opacity 0.8s linear;
}
// 离开效果
.slide-enter-to,
.slide-leave {
  opacity: 1;
}
</style>
